package com.service.store.impl;

import com.dao.store.QuestionItemDao;
import com.domain.store.QuestionItem;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.store.QuestionItemService;
import com.utils.MapperUtils;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

public class QuestionItemServiceImpl implements QuestionItemService {
private QuestionItemDao questionItemDao;

    public void setQuestionItemDao(QuestionItemDao questionItemDao) {
        this.questionItemDao = questionItemDao;
    }

    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo findAll(String qusetid,int page, int size) {

            Page pages = PageHelper.startPage(page,size);
            questionItemDao.findAll(qusetid);
           return new PageInfo(pages);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public QuestionItem findById(String id) {
       return questionItemDao.findById(id);
    }

    /**
     * 添加操作
     * @param questionItem
     */
    @Override
    public String save(QuestionItem questionItem,boolean flag) {
        String id = UUID.randomUUID().toString();
            questionItem.setId(id);
            if (flag) {
                //防止图片重名
                questionItem.setPicture(id);
            }
            questionItemDao.save(questionItem);
        return id;
    }

    /**删除操作
     * @param questionItem
     */
    @Override
    public void delete(QuestionItem questionItem) {
       questionItemDao.delete(questionItem);
    }

    /**
     * 修改操作
     * @param questionItem
     */
    @Override
    public void update(QuestionItem questionItem,boolean flag) {
        questionItemDao.update(questionItem);
    }
}
